package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.WorkSummary;
import com.ruoyi.system.service.IWorkSummaryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工作总结Controller
 *
 * @author ruoyi
 * @date 2024-04-25
 */
@RestController
@RequestMapping("/system/work/summary")
public class WorkSummaryController extends BaseController
{
    @Autowired
    private IWorkSummaryService workSummaryService;

    /**
     * 查询工作总结列表
     */
    @PreAuthorize("@ss.hasPermi('system:work:summary:list')")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody WorkSummary workSummary)
    {
        setStartPage(workSummary.getPageNum(),workSummary.getPageSize());
        List<WorkSummary> list = workSummaryService.selectWorkSummaryList(workSummary);
        return getDataTable(list);
    }

    /**
     * 获取工作总结详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:work:summary:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(workSummaryService.selectWorkSummaryById(id));
    }

    /**
     * 新增工作总结
     */
    @PreAuthorize("@ss.hasPermi('system:work:summary:add')")
    @Log(title = "工作总结", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody WorkSummary workSummary)
    {
        workSummary.setCreateBy(String.valueOf(getUserId()));
        workSummary.setCreateName(getUsername());
        return toAjax(workSummaryService.insertWorkSummary(workSummary));
    }

    /**
     * 修改工作总结
     */
    @PreAuthorize("@ss.hasPermi('system:work:summary:edit')")
    @Log(title = "工作总结", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody WorkSummary workSummary)
    {
        return toAjax(workSummaryService.updateWorkSummary(workSummary));
    }

    /**
     * 删除工作总结
     */
    @PreAuthorize("@ss.hasPermi('system:work:summary:remove')")
    @Log(title = "工作总结", businessType = BusinessType.DELETE)
	@DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(workSummaryService.deleteWorkSummaryById(id));
    }
}
